#!/bin/bash

# Tiny QA 停止脚本

echo "=== 停止 Tiny QA 服务 ==="

# 查找并停止Tiny QA进程
pids=$(ps aux | grep "python app.py" | grep -v grep | awk '{print $2}')

if [ -z "$pids" ]; then
    echo "Tiny QA 服务未运行"
    exit 0
fi

echo "找到 Tiny QA 进程: $pids"

# 优雅停止进程
for pid in $pids; do
    echo "停止进程 $pid..."
    kill -TERM $pid
    
    # 等待进程结束
    for i in {1..10}; do
        if ! kill -0 $pid 2>/dev/null; then
            echo "进程 $pid 已停止"
            break
        fi
        sleep 1
    done
    
    # 如果进程仍在运行，强制杀死
    if kill -0 $pid 2>/dev/null; then
        echo "强制停止进程 $pid..."
        kill -KILL $pid
    fi
done

echo "Tiny QA 服务已停止" 